package ro.tm.uvt.lp.raccoon.catchGame.entities.physicalObjects;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;

import java.util.ArrayList;
import java.util.List;

import ro.tm.uvt.lp.raccoon.catchGame.entities.PhysicalObject;
import ro.tm.uvt.lp.raccoon.catchGame.entities.perceptions.CookieOdor;
import ro.tm.uvt.lp.raccoon.catchGame.environment.Environment;

/**
 * Created by user on 1/14/2015.
 */
public class Food extends PhysicalObject {

    private List<CookieOdor> smellEntities=new ArrayList<CookieOdor>();


    public Food(Sprite sprite, int x, int y){
        super(sprite);
//        this.x=x;
//        this.y=y;
        this.setPosition(x,y);
        //for each cookie created we add an odor entity that can be sensed by the raccoon in all direction
        //of movement we such an odor.
        CookieOdor co0=new CookieOdor(new Sprite(new Texture("entities/odor40.png")));
        co0.setPosition(getX(),getY());
//        Environment.INSTANCE.addOdor(co1);
        this.addSmellEntity(co0);

        //up
        CookieOdor co1=new CookieOdor(new Sprite(new Texture("entities/odor40.png")));
        co1.setPosition(getX(),getY()+Environment.INSTANCE.getTileHeight());
//        Environment.INSTANCE.addOdor(co1);
        this.addSmellEntity(co1);
        //right
        CookieOdor co2=new CookieOdor(new Sprite(new Texture("entities/odor40.png")));
        co2.setPosition(getX()+Environment.INSTANCE.getTileWidth(),getY());
//        Environment.INSTANCE.addOdor(co2);
        this.addSmellEntity(co2);
        //down
        CookieOdor co3=new CookieOdor(new Sprite(new Texture("entities/odor40.png")));
        co3.setPosition(getX(),getY()-Environment.INSTANCE.getTileHeight());
//        Environment.INSTANCE.addOdor(co3);
        this.addSmellEntity(co3);
        //left
        CookieOdor co4=new CookieOdor(new Sprite(new Texture("entities/odor40.png")));
        co4.setPosition(getX()-Environment.INSTANCE.getTileWidth(),getY());
//        Environment.INSTANCE.addOdor(co4);
        this.addSmellEntity(co4);
    }

    public void addSmellEntity(CookieOdor co){
        this.smellEntities.add(co);
    }

    public List<CookieOdor> getOdor(){
        return this.smellEntities;
    }

    public void deleteSmell(){
        for(CookieOdor co:this.smellEntities){
            co.getTexture().dispose();
            this.smellEntities.remove(co);
//            Environment.INSTANCE.getOdorList().remove(co);
        }
    }

}
